package com.onpositive.page.pagerendering;

import java.io.ByteArrayInputStream;
import java.io.InputStream;

public class ModifyPageContentFormRenderer {

	public final static String FIELD_WITH_CONTENT_NAME = "commitData";
	
	private String resContent;
	private String handlerURI;

	public ModifyPageContentFormRenderer(String resContent, String handlerURI) {
		this.resContent = resContent;
		this.handlerURI = handlerURI;
	}

	public String getContent() {
		StringBuilder sb = new StringBuilder();
		sb.append("<form id=\"editForm\" action=\""+ handlerURI +"\" method=\"post\">");
		sb.append("<table>");
		sb.append("<tr>");
		sb.append("<td>");
		sb.append("<textarea name=\""+FIELD_WITH_CONTENT_NAME+"\""+ ">" +resContent+"</textarea>");// resContent 
		sb.append("</td>");
		sb.append("</tr>");
		sb.append("<tr>");
		sb.append("<td>");
		sb.append("<input type=\"submit\" value=\"Commit\">");
		sb.append("</td>");
		sb.append("</tr>");
		sb.append("</table>");
		sb.append("</form>");
		
		return sb.toString();
	}
	
	public InputStream getContentAsStream(){
		return new ByteArrayInputStream(getContent().getBytes());
	}
}
